package Java7_Concurrency_Cookbook.concurrency_test.use_logging;

import java.io.IOException;
import java.util.logging.*;

/**
 * @author lixiangke
 * @date 2017/12/5
 */
public class MyLogger {
    private static Handler handler;
    public static Logger getLogger(String name) throws IOException {
        Logger logger = Logger.getLogger(name);
        logger.setLevel(Level.ALL);
        if (handler == null) {
            handler = new FileHandler("recipe8.log");
            Formatter formatter = new MyFormatter();
            handler.setFormatter(formatter);
        }
        if (logger.getHandlers().length == 0) {
            logger.addHandler(handler);
        }
        return logger;
    }
}
